#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
class Graph
{
    struct Edge
    {
        int vs,vt,w;
        Edge* next;
        void set(int a,int b,int c,Edge* nt = NULL)
        {
            vs=a,vt=b,w=c,next=nt;
        }
    };
#define EACH(i,vs) for(Edge* i=head[vs];i;i=i->next)
  public:
  int vn,arcn;
  Edge *edge,**head;
  Graph(int n,int m)
  {
    vn=n+1,arcn=0;
    edge = new Edge[m+10];
    head = new Edge*[n+10];
    fill(head,head+n+10,(Edge*)NULL);
  }
  ~Graph()
  {
    delete(edge);
    delete(head);
  }
  void AddArc(int vs,int vt,int w)
  {
    edge[arcn].set(vs,vt,w,head[vs]);
    head[vs]=&edge[arcn++];
  }
  bool Legal(int dist24)
  {
    vector<int> dist(25,0);
    vector<int> cnt(25,1);
    vector<bool> done(25,true);
    queue<int> q;
    dist[24] = dist24;
    REP(i,25) q.push(24-i);
    while(!q.empty())
    {
        int vs = q.front();q.pop();
        done[vs] = false;
        EACH(ep,vs) if(dist[vs]+ep->w>dist[ep->vt])
        {
            dist[ep->vt] =  dist[vs]+ep->w;
            if(++cnt[ep->vt]>=25) return false;
            if(!done[ep->vt])
            {
                q.push(ep->vt);
                done[ep->vt] = true;
            }
        }
    }
    return dist[0]==0;
  }
};
int main()
{
    int T;
    int ri[24];
    cin>>T;
    while(T--)
    {
        REP(i,24) scanf("%d",ri+i);
        int n;
        vector<int> cnt(24,0);
        cin>>n;
        REP(i,n)
        {
            int ti;
            scanf("%d",&ti);
            cnt[ti]++;
        }
        Graph g(30,24*3);
        FOR(i,7,24) g.AddArc(i+1-8,i+1,ri[i]);
        REP(i,24)
        {
            g.AddArc(i+1,i,-cnt[i]);
            g.AddArc(i,i+1,0);
        }
        REP(i,7) g.AddArc(i+17,i+1,ri[i]);
        int ans = -1;
        int high = n,low = 0;
        while(low<=high)
        {
            int mid = (low+high)>>1;
            REP(j,7) g.head[j+17]->w=ri[j]-mid;
            if(g.Legal(mid)) high=mid-1;
            else low = mid+1;
        }
        if(low==n+1) puts("No Solution");
        else printf("%d\n",low);
    }
	return 0;
}
